using System.Drawing;
using System.Media;

namespace MicropleSoft.Controls.DialogBox
{
    internal partial class MessageBox : DevExpress.XtraEditors.XtraForm
    {
        const int DefBtnWidth = 75;  
        const int GapTwoBtns = 150;
        const int GapTriBtns = 100;

        public MessageBox()
        {
            InitializeComponent();
            this.lblText.BackColor = this.BackColor;
        }

        internal void SetIcon(DialogBox.CustomMessageBox.MsgBoxIcons icon)
        {
            // set icon
            if (icon == DialogBox.CustomMessageBox.MsgBoxIcons.None)
                this.pbxIcon.Image = null;
            else
                this.pbxIcon.Image = DialogBox.CustomMessageBox.GetImage(icon);
            switch (icon)
            { 
                case DialogBox.CustomMessageBox.MsgBoxIcons.Error:
                case DialogBox.CustomMessageBox.MsgBoxIcons.Warn:
                    this.lblText.ForeColor = Color.Red;
                    break;
                case DialogBox.CustomMessageBox.MsgBoxIcons.Good:
                case DialogBox.CustomMessageBox.MsgBoxIcons.Info:
                    this.lblText.ForeColor = Color.Blue;
                    break;
                case DialogBox.CustomMessageBox.MsgBoxIcons.None:
                case DialogBox.CustomMessageBox.MsgBoxIcons.Question:
                    this.lblText.ForeColor = Color.Black;
                    break;
            }
        }
        internal void SetCaption(string caption)
        {
            this.Text = caption;
        }
        internal void SetMsg(string msg)
        {
            this.lblText.Text = msg;
        }
        internal void LayoutBtns(DialogBox.CustomMessageBox.MsgBoxButtons btns)
        {
            // Layout the buttons
            // ------- just visible the OK buttons, as it is always required
            this.btnCancel.Visible = false;
            this.btnNo.Visible = false;
            this.btnOK.Visible = true;

            // calculate their positions
            switch (btns)
            {
                case DialogBox.CustomMessageBox.MsgBoxButtons.Ok:
                    this.btnOK.Visible = true;
                    this.btnOK.Left = (this.Width - DefBtnWidth) / 2;
                    this.AcceptButton = this.btnOK;
                    break;
                case DialogBox.CustomMessageBox.MsgBoxButtons.OkCancel:
                    this.btnOK.Visible = true;
                    this.btnNo.Visible = true;
                    this.btnOK.Left = (this.Width - 2 * DefBtnWidth - GapTwoBtns) / 2;
                    this.btnNo.Left = this.btnOK.Left + DefBtnWidth + GapTwoBtns;
                    this.AcceptButton = this.btnOK;
                    this.CancelButton = this.btnNo;                    
                    break;
                case DialogBox.CustomMessageBox.MsgBoxButtons.OkNoCancel:
                    this.btnOK.Visible = true;
                    this.btnNo.Visible = true;
                    this.btnCancel.Visible = true;
                    this.btnOK.Left = (this.Width - 3 * DefBtnWidth - 2 * GapTriBtns) / 2;
                    this.btnNo.Left = this.btnOK.Left + DefBtnWidth + GapTriBtns;
                    this.btnCancel.Left = this.btnNo.Left + DefBtnWidth + GapTriBtns;
                    this.AcceptButton = this.btnOK;
                    this.CancelButton = this.btnCancel;
                    break;
            }
        }
        internal static void DoBeep(DialogBox.CustomMessageBox.MsgBoxIcons icon)
        {
            // Play the associated SystemSound
            switch (icon)
            {
                case DialogBox.CustomMessageBox.MsgBoxIcons.Error:
                    SystemSounds.Hand.Play();
                    break;
                case DialogBox.CustomMessageBox.MsgBoxIcons.Good:
                case DialogBox.CustomMessageBox.MsgBoxIcons.Info:
                    SystemSounds.Asterisk.Play();
                    break;
                case DialogBox.CustomMessageBox.MsgBoxIcons.Question:
                    SystemSounds.Question.Play();
                    break;
                default:
                    SystemSounds.Beep.Play();
                    break;
            }
        }
    }
}

